package com.example.freshfoodproject.controller;

import com.example.freshfoodproject.entry.Delivery;
import com.example.freshfoodproject.service.DeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DeliveryController {
    @Autowired
    private DeliveryService deliveryService;

    /**
     * 动态生成地址的单选框
     * @return 返回地址表的所有数据
     */
    @RequestMapping("/loadDelivery")
    @ResponseBody
    public List<Delivery> loadDelivery(){
        return deliveryService.findAll();
    }

    /**
     * 将前端输入的所有信息存入到地址表中
     * @param address 前端输入的收货地址
     * @param recipient 前端输入的收件人
     * @param code 前端输入的邮编
     * @param phone 前端输入的手机号码
     */
    @RequestMapping("/addDelivery")
    @ResponseBody
    public void addDelivery(String address,String recipient,String code,String phone){
        Delivery delivery = new Delivery();
        delivery.setAddress(address);
        delivery.setRecipient(recipient);
        delivery.setCode(code);
        delivery.setPhone(phone);
        deliveryService.addDelivery(delivery);
    }
}
